package com.chinafree.business.controller;

import com.chinafree.business.model.param.CompanyParam;
import com.chinafree.business.model.queryCondition.BaseQueryCondition;
import com.chinafree.business.model.result.BaseUserResult;
import com.chinafree.business.model.result.CompanyResult;
import com.chinafree.business.model.result.UserBaseMessageResult;
import com.chinafree.business.model.result.UserResumeResult;
import com.chinafree.business.service.CompanyService;
import com.chinafree.common.model.enumeration.ResponseCodeEnum;
import com.chinafree.common.model.request.RequestParameter;
import com.chinafree.common.model.response.BaseResponse;
import com.chinafree.common.model.response.EntityResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("company")
public class CompanyController extends BaseController {

    @Autowired
    private CompanyService companyService;

    @ApiOperation(value = "获得公司信息")
    @GetMapping("/getCompanyInfoByToken")
    private EntityResponse<CompanyResult> getCompanyInfoByToken(@RequestParam("token") String token) {
        CompanyResult companyInfo = companyService.getCompanyInfo(getCompanyId(token));
        return new EntityResponse<>(ResponseCodeEnum.SUCCESS, "查询成功", companyInfo);
    }

 
    @ApiOperation(value = "获得公司信息")
    @PostMapping("/getCompanyInfo")
    private EntityResponse<CompanyResult> getCompanyInfo() {
        CompanyResult companyInfo = companyService.getCompanyInfo(null);
        return new EntityResponse<>(ResponseCodeEnum.SUCCESS, "查询成功", companyInfo);
    }

    @ApiOperation(value = "更新公司信息")
    @PostMapping("/update")
    private BaseResponse update(@RequestBody RequestParameter<CompanyParam> jobParamRequestParameter) {
        companyService.update(jobParamRequestParameter.getBody());
        return BaseResponse.success();
    }

    @ApiOperation(value = "插入公司信息")
    @PostMapping("/insert")
    private EntityResponse<Map<String, String>> insert(
            @RequestBody RequestParameter<CompanyParam> jobParamRequestParameter) {
        String token = companyService.insert(jobParamRequestParameter.getBody());
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        return new EntityResponse<>(ResponseCodeEnum.SUCCESS, "插入成功", map);
    }


    @ApiOperation(value = "获得公司信息")
    @PostMapping("/getCompany")
    private EntityResponse<List<CompanyResult>> getCompany(@RequestBody RequestParameter<BaseQueryCondition> condition) {
        List<CompanyResult> companyInfo = companyService.getCompany(condition.getBody());
        return new EntityResponse<>(ResponseCodeEnum.SUCCESS, "查询成功", companyInfo);
    }
}
